package com.htthorizon.powersupply.mapper;

public class SqlProvider {

    public String selectLatestNonNullColumn() {
        StringBuilder sqlBuilder = new StringBuilder();
        sqlBuilder.append("SELECT MAX(col) as latest_non_null_column FROM (");

        // 开始构建UNION ALL部分
        for (int i = 1; i <= 96; i++) {
            if (i > 1) {
                sqlBuilder.append(" UNION ALL ");
            }
            sqlBuilder.append("SELECT " ).append(i).append(" AS col, val").append(i).append(" FROM rds_grid_tg_volt_df");
        }

        // 结束子查询并添加条件
        sqlBuilder.append(") t WHERE val1 IS NOT NULL");

        return sqlBuilder.toString();
    }
}
